package com.luoc.service.impl;

import com.luoc.service.Itrerator;

import java.util.List;

/**
 * @author luoc
 */
public class ConcreteIterator implements Itrerator {


    /**
     *  聚合类
     */
    private ConcreteAggrate aggrate;
    /**
     * 遍历数据
     */
    private List<Object> productList;
    /**
     *  游标 记录当前正序访问的位置
     */
    private int cursor;

    /**
     * 记录倒序访问的位置
     */
    private int descOrderCusor;

    @Override
    public Object next() {
        cursor++;
        return productList.get(cursor);
    }

    public ConcreteIterator(ConcreteAggrate aggrate) {
        this.aggrate = aggrate;
        productList = aggrate.getProductList();
        cursor =0;
        descOrderCusor = productList.size();
    }

    @Override
    public Object prev() {
        return productList.get(cursor);
    }

    @Override
    public Object currentItem() {
        return productList.get(cursor);
    }

    @Override
    public boolean hasNext() {
        return productList.size() > cursor;
    }
}
